package it.storm.solution;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 1929. 数组串联
 * https://leetcode-cn.com/problems/concatenation-of-array/
 */
public class Solutions_1929 {
    public static void main(String[] args) {
        int[] nums1 = {1, 2, 1};  // output: {1, 2, 1, 1, 2, 1}
        int[] nums2 = {1, 3, 2, 1};  // output: {1, 3, 2, 1, 1, 3, 2, 1}

        List<int[]> inputs = new ArrayList<>();
        inputs.add(nums1);
        inputs.add(nums2);

        for (int[] input : inputs) {
            int[] result = getConcatenation(input);
            System.out.println(Arrays.toString(result));
        }
    }

    public static int[] getConcatenation(int[] nums) {
        int len = nums.length;
        int[] res = new int[len * 2];
        // 复制 nums 数组至 res 数组
        System.arraycopy(nums, 0, res, 0, len);
        System.arraycopy(nums, 0, res, len, len);
        return res;
    }
}
